#Obtaining the full sample of all authors (do only once)#

library(igraph)
library(reshape)
source("getntwrks7auth.R")
source("netprod_7authorsbygender.R")
source("analyzenetw.R")
data<-read.csv("networkgendert7017.csv",header=TRUE)
colnames(data) <- c("articleid", "auth1","gender1","myear1","auth2", "gender2","myear2","auth3","gender3","myear3","auth4","gender4","myear4","auth5","gender5","myear5","auth6","gender6","myear6","auth7","gender7","myear7","nauthors","year","journalid","prod","jcr","ais","prodd","jcrd","aisd") 

# endyears and length to compute networks
ks <- 5
for (k in ks) {
 endyears <- (1970+k-1):2017
  for (endyear in endyears) {
    startyear <- endyear - k+1
    y <- subset(data,year>=startyear & year<=endyear)
    g <- getnetwork(startyear,endyear, data)
    y$auth7[is.na(y$auth7)]<--6 
    y$auth6[is.na(y$auth6)]<--5 
    y$auth5[is.na(y$auth5)]<--4 
    y$auth4[is.na(y$auth4)]<--3 
    y$auth3[is.na(y$auth3)]<--2 
    y$auth2[is.na(y$auth2)]<--1  
    V(g)$deg <- degree(g)
    netprodx<- sapply(V(g)[deg>0],netprodg,g,y,endyear)   
       V(g)[deg>0]$netprodmale <-netprodx[1,]    
         V(g)[deg>0]$netprodfemale <-netprodx[2,]   
           V(g)[deg>0]$netprodm <-netprodx[3,]   
             V(g)[deg>0]$netaismale <-netprodx[4,]    
               V(g)[deg>0]$netaisfemale <-netprodx[5,]  
                 V(g)[deg>0]$papersmale <-netprodx[6,] 
                   V(g)[deg>0]$papersfemale <-netprodx[7,] 
                      V(g)[deg>0]$papersm <-netprodx[8,] 
                        V(g)[deg>0]$nmaleco <-netprodx[9,] 
                          V(g)[deg>0]$nfemaleco <-netprodx[10,] 
                            V(g)[deg>0]$nmco <-netprodx[11,] 
                               V(g)[deg>0]$tmale <-netprodx[12,] 
                                V(g)[deg>0]$tfemale <-netprodx[13,] 
                                 V(g)[deg>0]$tm <-netprodx[14,] 
                                    V(g)$auth<-V(g)
    d<-data.frame(V(g)$auth,V(g)$deg,V(g)$netprodmale,V(g)$netprodfemale,V(g)$netprodm, V(g)$netaismale, V(g)$netaisfemale, V(g)$papersmale,V(g)$papersfemale,V(g)$papersm,V(g)$nmaleco,V(g)$nfemaleco,V(g)$nmco,V(g)$tmale,V(g)$tfemale,V(g)$tm)
    write.csv(d,file=paste("networkprod", endyear, "_", k, "y.csv", sep=""),na=".")
  }
}

            
 